Page({
  data: {
    id: '',
    imgsrc: '',
    name: '',
    score: '',
    comment: '',
    cat: '',
    country: '',
    showing: '',
    duration: '',
    desc: '',
    localover: '../../assets/images/icon_d_arrow_down.png',
    hideText: true,
    hideClass: 'up',
    comments: [],
  },
  onLoad: function (options) {
    // 生命周期函数--监听页面加载
    var that = this
    var id = options.id

    var url = 'https://api.maoyan.com/mmdb/movie/v5/' + id + '.json'
    var url2 = 'https://api.maoyan.com/mmdb/comments/movie/v2/' + id + '.json'
    wx.request({
      url: url,
      data: {
        ci: 50
      },
      method: 'GET',
      success: function (res) {
        /**
         * 获取电影基本信息
         */
        var value = res.data.data.movie
        // console.log(value)
        value.img = value.img.replace('w.h', '150.150')
        that.setData({
          imgsrc: value.img,
          name: value.nm,
          score: value.sc,
          comment: value.snum,
          cat: value.cat,
          country: value.src,
          showing: value.rt,
          duration: value.dur,
          desc:value.dra
        })
        /**
         * 获取评论
         */
        wx.request({
          url: url2,
          data: {
            limit: 3,
            offset: 0,
            tag: 0
          },
          method: 'GET',
          success: function (res) {
            that.setData({
              comments: res.data.cmts
            })
          }
        })
      }
    })
  },
  showall: function () {
    var that = this;
    var hide = that.data.hideText;
    var hideClass = that.data.hideClass == 'up' ? 'down' : 'up';
    that.setData({
      hideText: !hide,
      hideClass: hideClass
    })
  }
})